<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>mode</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="MixerClear.html" title="MixerClear" />
    <link rel="next" href="modmatrix.html" title="modmatrix" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">mode</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="MixerClear.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="modmatrix.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="mode"></a>
      <div class="titlepage"></div>
      <a id="IndexMode" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">mode</span>
        </h2>
        <p>mode — 
      A filter that simulates a mass-spring-damper system
    </p>
      </div>
      <div class="refsect1">
        <a id="idp126048688"></a>
        <h2>Description</h2>
        <p>
      Filters the incoming signal with the specified resonance frequency and
      quality factor. It can also be seen as a signal generator for high quality
      factor, with an impulse for the excitation. You can combine several modes
      to built complex instruments such as bells or guitar tables.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp126050160"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">aout <span class="command"><strong>mode</strong></span> ain, xfreq, xQ [, iskip]</pre>
      </div>
      <div class="refsect1">
        <a id="idp126052384"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>iskip</em></span>
      (optional, default=0) -- if non zero skip the initialisation of the
      filter.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp126054096"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>aout</em></span> -- filtered signal
    </p>
        <p>
      <span class="emphasis"><em>ain</em></span> -- signal to filter
    </p>
        <p>
      <span class="emphasis"><em>xfreq</em></span> -- resonant frequency of the filter
      </p>
        <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Warning: Warning">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Warning]" src="images/warning.png" />
              </td>
              <th align="left">Warning</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
          This filter becomes unstable if <span class="emphasis"><em>sr</em></span>/<span class="emphasis"><em>xfreq</em></span> &lt;
          pi (e.g <span class="emphasis"><em>xfreq</em></span> &gt; 14037 Hz @ 44 kHz)
        </p>
              </td>
            </tr>
          </table>
        </div>
        <p>
    </p>
        <p>
      <span class="emphasis"><em>xQ</em></span> -- quality factor of the filter
    </p>
        <p>The resonance time is roughly proportional to <span class="emphasis"><em>xQ</em></span>/<span class="emphasis"><em>xfreq</em></span>.</p>
        <p>
      See <a class="link" href="MiscModalFreq.html" title="Appendix E. Modal Frequency Ratios"><em class="citetitle">Modal Frequency Ratios</em></a> for frequency ratios of real instruments which can be used to determine the values of <span class="emphasis"><em>xfreq</em></span>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp126064032"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the mode opcode. It uses the file <a class="ulink" href="examples/mode.csd" target="_top"><em class="citetitle">mode.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp126065888"></a>
          <p class="title">
            <strong>Example 521. Example of the mode opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
<span class="comment">; Audio out   Audio in    No messages</span>
-odac           -iadc     -d     <span class="comment">;;;RT audio I/O</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o moogvcf.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="comment">; Initialize the global variables.</span>
<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">kr</span> <span class="op">=</span> 4410
<span class="ohdr">ksmps</span> <span class="op">=</span> 10
<span class="ohdr">nchnls</span> <span class="op">=</span> 2

<span class="oblock">instr</span> 1<span class="comment">; 2 modes excitator</span>

idur <span class="opc">init</span> p3
ifreq11 <span class="opc">init</span> p4
ifreq12 <span class="opc">init</span> p5
iQ11    <span class="opc">init</span> p6
iQ12    <span class="opc">init</span> p7
iamp    <span class="opc">init</span> <span class="opc">ampdb</span>(p8)
ifreq21 <span class="opc">init</span> p9
ifreq22 <span class="opc">init</span> p10
iQ21    <span class="opc">init</span> p11
iQ22    <span class="opc">init</span> p12

<span class="comment">; to simulate the shock between the excitator and the resonator</span>
ashock  <span class="opc">mpulse</span>  3,0 

aexc1  <span class="opc">mode</span> ashock,ifreq11,iQ11
aexc1 <span class="op">=</span> aexc1<span class="op">*</span>iamp
aexc2  <span class="opc">mode</span> ashock,ifreq12,iQ12
aexc2 <span class="op">=</span> aexc2<span class="op">*</span>iamp


aexc <span class="op">=</span> (aexc1<span class="op">+</span>aexc2)<span class="op">/</span>2

<span class="comment">;"Contact" condition : when aexc reaches 0, the excitator looses </span>
<span class="comment">;contact with the resonator, and stops "pushing it"</span>
aexc limit aexc,0,3<span class="op">*</span>iamp 

<span class="comment">; 2modes resonator</span>

ares1  <span class="opc">mode</span> aexc,ifreq21,iQ21
ares2  <span class="opc">mode</span> aexc,ifreq22,iQ22

ares <span class="op">=</span> (ares1<span class="op">+</span>ares2)<span class="op">/</span>2

<span class="opc">display</span> aexc<span class="op">+</span>ares,p3
<span class="opc">outs</span>  aexc<span class="op">+</span>ares,aexc<span class="op">+</span>ares

<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="comment">;wooden excitator against glass resonator</span>
<span class="stamnt">i</span>1 0 8  1000   3000  12  8  70  440   888   500  420 

<span class="comment">;felt against glass</span>
<span class="stamnt">i</span>1 4 8  80   188  8  3  70  440   888   500  420 

<span class="comment">;wood against wood</span>
<span class="stamnt">i</span>1 8 8  1000   3000  12  8  70  440  630   60  53 

<span class="comment">;felt against wood</span>
<span class="stamnt">i</span>1 12 8  80   180  8  3  70  440  630   60  53 


<span class="stamnt">i</span>1 16 8  1000   3000  12  8  70  440  888   2000  1630
<span class="stamnt">i</span>1 23 8  80   180  8  3  70  440  888   2000  1630


<span class="comment">;With a metallic excitator</span>

<span class="stamnt">i</span>1 33 8 1000  1800  1000  720  70   440   882  500  500
<span class="stamnt">i</span>1 37 8 1000  1800  1000  850  70   440   630  60  53

<span class="stamnt">i</span>1 42 8 1000  1800  2000  1720  70   440   442  500  500


<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp126070176"></a>
        <h2>Credits</h2>
        <p>Original UDO and documentation/example by François Blanc</p>
        <p>Opcode translation to C-code by Steven Yi</p>
        <p>New in version 5.04</p>
        <p>Audio rate parameters introduced in version 6.02</p>
        <p>November 2013.</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="MixerClear.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="modmatrix.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">MixerClear </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> modmatrix</td>
        </tr>
      </table>
    </div>
  </body>
</html>
